home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / lk_df.zip / DF_CMD.C < prev    next >
C/C++ Source or Header  |  1993-02-16  |  2KB  |  73 lines

  1. /*
  2.  * df_cmd.c - ancillary routines for checking df's command line
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <dir.h>
  7. #include <ctype.h>
  8. #include "dfbits.h"
  9.  
  10. /* see if we have an argument on the command line.  If so, just print help
  11.  * and return non-zero; otherwise, return zero.  Crude but effective.
  12.  */
  13. int found_an_option( int ac, char **av )
  14. {
  15.     int i, found_one;
  16.     char c;
  17.     char prgname[9];
  18.  
  19.     for( i = 1, found_one = 0; i <= ac; ++i )
  20.     {
  21.         if( av[i][0] == '/' || av[i][0] == '-' )
  22.         {
  23.             found_one = 1;
  24.             break;
  25.  
  26.         }
  27.     }
  28.  
  29.     if( found_one )
  30.     {
  31.         if( tolower(av[i][1]) != 'h' && av[i][1] != '?' )
  32.             fprintf( stderr, "invalid option\n\n" );
  33.  
  34.         fnsplit( av[0], NULL, NULL, prgname, NULL );
  35.         fprintf( stderr, "usage: %s [/? | /h | [drive...]]\n", prgname );
  36.         fprintf( stderr, "       /? or /h : prints this message\n" );
  37.         fprintf( stderr, "       drive... is 0 or more drives (A: through Z:)\n" );
  38.         fprintf( stderr, "       run df with no parameters to check all drives\n" );
  39.  
  40.         return( 1 );
  41.     }
  42.     else
  43.         return( 0 );
  44. }
  45.  
  46.  
  47.  
  48. /*
  49.  * scan the command line for drive arguments, update drive flags as needed
  50.  */
  51. void check_drive_args( int ac, char **av, long *dbits )
  52. {
  53.     int i;
  54.     char c;
  55.  
  56.  
  57.     if( ac > 1 )    /* then we presumably have some drive args */
  58.     {
  59.         CLEAR_ALL( *dbits );
  60.         for( i = 1; i <= ac; ++i )
  61.         {
  62.             if( isalpha(c=av[i][0]) )        // we're looking at the 1st
  63.             {                                // char of each command line
  64.                 tolower(c);                  // arg & junking it if it's
  65.                 SET_BIT( *dbits, (c-'a') );  // not a letter
  66.             }
  67.         }
  68.  
  69.         if( *dbits == 0 )         /* none of the args were valid */
  70.             SET_ALL( *dbits );
  71.     }
  72. }
  73.